/**
 * Copyright (C) 2014 Luvina Software Company
 * BaseDaoImpl.java, Dec 15, 2014, Nguyen Huu Luan LA11_AM
 *
 */
package net.luvina.manageuser.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import net.luvina.manageuser.dao.BaseDao;
import net.luvina.manageuser.utils.DatabaseProperties;

/**
 * Thức thi giao diện BaseDao.
 * 
 * @author luan
 * 
 */
public class BaseDaoImpl implements BaseDao {
	protected Connection connection = null;
	protected PreparedStatement preparedStatement = null;
	protected ResultSet rs = null;

	/*
	 * (non-Javadoc)
	 * 
	 * @see manageuser.dao.BaseDao#connectToDB()
	 */
	public boolean connectToDB() {
		boolean result = false;
		try {

			Class.forName(DatabaseProperties.getData("driver"));
			connection = DriverManager.getConnection(DatabaseProperties
					.getData("url"), DatabaseProperties.getData("user"),
					DatabaseProperties.getData("password"));
			result = true;
		} catch (Exception e) {
			System.out.println("an exception occur: " + e.getMessage());
		}
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see manageuser.dao.BaseDao#closeConnect()
	 */
	public void closeConnect() {
		if (connection != null) {
			try {
				connection.close();
			} catch (Exception e) {
				System.out.println("an exception occur: " + e.getMessage());
			}
			connection = null;
		}
	}

}
